package com.itbaizhan.controller;

import com.itbaizhan.pojo.Comment;
import com.itbaizhan.result.BaseResult;
import com.itbaizhan.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author spf
 * @date 2024/3/4
 * @time 19:58
 */
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping("/save/{id}")
    public BaseResult save(@PathVariable("id") String orderId, @RequestBody Comment comment) {
        commentService.saveComment(orderId, comment);
        return BaseResult.ok();
    }

    @GetMapping("/findByPage")
    public BaseResult<List<Comment>> findByPage(@RequestParam("itemId") String itemId,
                                                @RequestParam("page") int page,
                                                @RequestParam(value = "rows", defaultValue = "5") int rows) {
        List<Comment> commentList = commentService.findByPage(itemId, page, rows);
        return BaseResult.ok(commentList);
    }

}
